package cn.xizikelif.org.service.impl;

import cn.xizikelif.basic.service.impl.BaseServiceImpl;
import cn.xizikelif.org.domain.Permission;
import cn.xizikelif.org.domain.Systemdictionarytype;
import cn.xizikelif.org.mapper.PermissionMapper;
import cn.xizikelif.org.mapper.SysTypeMapper;
import cn.xizikelif.org.service.IPermissionService;
import cn.xizikelif.org.service.ISysTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class SysTypeServiceImpl extends BaseServiceImpl<Systemdictionarytype> implements ISysTypeService {
        @Autowired
        private SysTypeMapper mapper;


        /* 无限级数 map 玩法， 双层for循环，100*100*/
       /* @Override
        public List<Permission> tree() {
                List<Permission> result = new ArrayList<>();
                // .查询所有出所有数据
                List<Permission> departmentsAll = mapper.findAll();
                // 在内存中拼接·部门·
                for (Permission dept :  departmentsAll) {
                        if(null == dept.getParentId()) {
                                result.add(dept);
                        }else {
                                for (Permission parent : departmentsAll) {
                                        if(dept.getParentId().equals(parent.getId())){
                                                parent.getChildren().add(dept);
                                                break;
                                        }
                                }

                        }
                }
                return result;
        }*/

        /* 无限级数 map 玩法， for遍历100次，map遍历100次 */
      /*  @Override
        public List<Permission> tree() {
                List<Permission> result = new ArrayList<>();
                // .查询所有出所有数据
                List<Permission> departmentsAll = mapper.findAll();
                *//*将所有数据转成 key 和 value*//*
                Map<Long, Permission> departmentMap = departmentsAll.stream().collect(Collectors.toMap(Permission::getId, dept -> dept));
                // 在内存中拼接·部门·
                for (Permission dept :  departmentsAll) {
                        if(null == dept.getParentId()) {
                                result.add(dept);
                        }else {
                                Permission parent = departmentMap.get(dept.getParentId());
                                parent.getChildren().add(dept);
                                *//*for (Permission parent : departmentsAll) {
                                        if(dept.getParentId().equals(parent.getId())){
                                                parent.getChildren().add(dept);
                                                break;
                                        }*//*
                                }

                        }
                return result;
        }*/

}
